package com.tms.springboot.controller;



import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.tms.springboot.aggregation.pojo.PdOrder;
import com.tms.springboot.result.JsonResult;
import com.tms.springboot.result.ResultTool;
import com.tms.springboot.service.PdOrderService;
import com.tms.springboot.vo.PdOrderCityVo;
import com.tms.springboot.view.PageVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 订单 前端控制器
 * </p>
 *
 * @author cjj
 * @since 2023-06-14
 */
@RestController
@RequestMapping("/pd-order")
public class PdOrderController {

    @Autowired
    private PdOrderService orderService;


    /**
     *
     * 查询近7天订单数量
     * @param startDate
     * @param endDate
     * @return
     */
    @RequestMapping("/queryEverydayOrderNumber")
    public JsonResult queryEverydayOrderNumber(String startDate, String endDate){

        List<Map<String,Integer>> list =this.orderService.queryEverydayOrderNumber(startDate, endDate);
        return list !=null ? ResultTool.success(list) : ResultTool.fail();
    }



    //根据用户查询指定状态的订单,状态为0查所有
    @GetMapping("/querystatus")
    public JsonResult querystatus(String id,Integer status,String orderid){

        List<PdOrderCityVo> list=orderService.querystatus(id,status,orderid);
        return ResultTool.success(list);
    }
    /**
     *
     * 分页查询
     * @param pageVo
     * @return
     */

    @RequestMapping("/queryOrderPage")
    public JsonResult queryOrderPage(@RequestBody PageVo<PdOrder> pageVo){
        PageHelper.startPage(pageVo.getCurrentPage(),pageVo.getPageSize());
        LambdaQueryWrapper<PdOrder> lqw=new LambdaQueryWrapper<>();
        if (!StringUtils.isEmpty(pageVo.getCondition().getStatus())){
            lqw.eq(PdOrder::getStatus, pageVo.getCondition().getStatus());
        }
        if (!StringUtils.isEmpty(pageVo.getCondition().getSenderName())) {
            lqw.like(PdOrder::getSenderName, pageVo.getCondition().getSenderName());
        }
        if (!StringUtils.isEmpty(pageVo.getCondition().getSenderPhone())){
            lqw.eq(PdOrder::getSenderPhone, pageVo.getCondition().getSenderPhone());
        }
        if (!StringUtils.isEmpty(pageVo.getCondition().getSenderCountyId())){
            lqw.eq(PdOrder::getSenderCountyId, pageVo.getCondition().getSenderCountyId());
        }
        if (!StringUtils.isEmpty(pageVo.getCondition().getPaymentStatus())){
            lqw.eq(PdOrder::getPaymentStatus,pageVo.getCondition().getPaymentStatus());
        }
        if (!StringUtils.isEmpty(pageVo.getCondition().getReceiverName())){
            lqw.like(PdOrder::getReceiverName,pageVo.getCondition().getReceiverName());
        }
        if (!StringUtils.isEmpty(pageVo.getCondition().getReceiverPhone())){
            lqw.eq(PdOrder::getReceiverPhone,pageVo.getCondition().getReceiverPhone());
        }
        if (!StringUtils.isEmpty(pageVo.getCondition().getReceiverCityId())){
            lqw.eq(PdOrder::getReceiverCityId,pageVo.getCondition().getReceiverCityId());
        }
        List<PdOrder> list = this.orderService.list(lqw);


        return list !=null ? ResultTool.success(new PageInfo<>(list)) :ResultTool.fail();
    }


}
